﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TireService.Data;
using System.Web.Security;

namespace TireService.Web.View.AdminView
{
    public partial class TireSetPurchase : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Page.IsPostBack != true)
            {
                try
                {
                    if (Request.QueryString["Message"] != null)
                    {
                        lMessage.Text = Request.QueryString["Message"].ToString();
                    }
                }
                catch (Exception)
                {
                    // Nothing
                }

                try
                {
                    // Get tiresetid to either replace or deactivate
                    int TireSetId = Convert.ToInt32(Request.QueryString["TireSetId"]);

                    // Initiate data layer
                    TireServiceDB db = new TireServiceDB();

                    TireSet tireset = db.GetTireSet(TireSetId);

                    if (tireset == null)
                    {
                        throw new ArgumentException("Hjulsæt ikke fundet.");
                    }
                    else
                    {
                        string action = Convert.ToString(Request.QueryString["Action"]);

                        if (action == null)
                        {
                            throw new ArgumentException("Ingen handling valgt.");
                        }
                        else
                        {
                            if (action == "Deactivate")
                            {
                                // Deactivate selected tireset and create new tireset
                            }
                            else
                            {
                                if (action == "Replace")
                                {
                                    // Replace selected dummy tireset with new tireset
                                }
                                else
                                {
                                    throw new ArgumentException("Valgt handling eksisterer ikke.");
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    lMessage.Text = ex.Message.ToString();

                    //// Error occured - customer subscription not found. Hide deactivation panel and show subscription selection panel
                    //pDeactivateSubscription.Visible = false;
                    //pSubscriptionSelection.Visible = true;

                }
                finally
                {
                    upMessage.Update();
                }

            }
        }
    }
}